home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-11-08 | 9.7 KB | 370 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWLinShp.cpp
- // Release Version: $ 1.0d11 $
- //
- // Copyright: © 1993, 1995 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWOS.hpp"
-
- #ifndef FWLINSHP_H
- #include "FWLinShp.h"
- #endif
-
- #ifndef FWGRGLOB_H
- #include "FWGrGlob.h"
- #endif
-
- #ifndef FWGC_H
- #include "FWGC.h"
- #endif
-
- #ifndef FWINK_H
- #include "FWInk.h"
- #endif
-
- #ifndef FWSTYLE_H
- #include "FWStyle.h"
- #endif
-
- #ifndef FWGRUTIL_H
- #include "FWGrUtil.h"
- #endif
-
- #ifndef FWRASTER_H
- #include "FWRaster.h"
- #endif
-
- // ----- Foundation Includes -----
-
- #ifndef FWSTREAM_H
- #include "FWStream.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef _TRANSFORM_
- #include <Trnsform.xh>
- #endif
-
- //========================================================================================
- // RunTime Info
- //========================================================================================
-
- #if FW_LIB_EXPORT_PRAGMAS
- #pragma lib_export on
- #endif
-
- #ifdef FW_BUILD_MAC
- #pragma segment FWGraphics_LineShape
- #endif
-
- FW_DEFINE_CLASS_M1(FW_CLineShape, FW_CShape)
- FW_REGISTER_ARCHIVABLE_CLASS(FW_LLineShape, FW_CLineShape, FW_CLineShape::Read, FW_CShape::Write)
-
- //========================================================================================
- // class FW_CLineShape
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_CLineShape::FW_CLineShape
- //----------------------------------------------------------------------------------------
-
- FW_CLineShape::FW_CLineShape(const FW_CLineShape& other) :
- FW_CShape(other),
- fStart(other.fStart),
- fEnd(other.fEnd)
- {
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CLineShape::FW_CLineShape
- //----------------------------------------------------------------------------------------
-
- FW_CLineShape::FW_CLineShape() :
- FW_CShape(FW_kFrame, FW_kNormalInk, FW_kNormalStyle, FW_kNormalFont)
- // fStart and fEnd are initialzied to 0's by default constructors
- {
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CLineShape::FW_CLineShape
- //----------------------------------------------------------------------------------------
-
- FW_CLineShape::FW_CLineShape(FW_CFixed xStart, FW_CFixed yStart,
- FW_CFixed xEnd, FW_CFixed yEnd,
- const FW_PInk& ink,
- const FW_PStyle& style) :
- FW_CShape(FW_kFrame, ink, style, FW_kNormalFont),
- fStart(xStart, yStart),
- fEnd(xEnd, yEnd)
- {
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CLineShape::FW_CLineShape
- //----------------------------------------------------------------------------------------
-
- FW_CLineShape::FW_CLineShape(const FW_CPoint& start,
- const FW_CPoint& end,
- const FW_PInk& ink,
- const FW_PStyle& style) :
- FW_CShape(FW_kFrame, ink, style, FW_kNormalFont),
- fStart(start),
- fEnd(end)
- {
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CLineShape::FW_CLineShape
- //----------------------------------------------------------------------------------------
-
- FW_CLineShape::FW_CLineShape(FW_CReadableStream& archive) :
- FW_CShape(archive)
- {
- archive >> fStart;
- archive >> fEnd;
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CLineShape::~FW_CLineShape
- //----------------------------------------------------------------------------------------
-
- FW_CLineShape::~FW_CLineShape()
- {
- FW_START_DESTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CLineShape::operator=
- //----------------------------------------------------------------------------------------
-
- FW_CLineShape& FW_CLineShape::operator=(const FW_CLineShape& other)
- {
- if (this != &other)
- {
- FW_CShape::operator=(other);
-
- fStart = other.fStart;
- fEnd = other.fEnd;
- }
-
- return *this;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CLineShape::Render
- //----------------------------------------------------------------------------------------
-
- void FW_CLineShape::Render(FW_CGraphicContext& gc) const
- {
- gc.GetRasterizer()->RenderLine(gc,
- fStart, fEnd,
- GetRenderVerb(),
- fInk,
- fStyle);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CLineShape::RenderLine
- //----------------------------------------------------------------------------------------
-
- void FW_CLineShape::RenderLine(FW_CGraphicContext& gc,
- const FW_CPoint& start,
- const FW_CPoint& end,
- const FW_PInk& ink,
- const FW_PStyle& style)
- {
- gc.GetRasterizer()->RenderLine(gc,
- start, end,
- FW_kFrame,
- ink,
- style);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CLineShape::GetBounds
- //----------------------------------------------------------------------------------------
-
- void FW_CLineShape::GetBounds(FW_CGraphicContext& gc, FW_CRect& rect) const
- {
- FW_UNUSED(gc);
-
- rect.Set(fStart.x, fStart.y, fEnd.x, fEnd.y);
- rect.Sort();
- FW_CFixed halfPen = GetPenSize().Half();
- rect.Inset(-halfPen, -halfPen);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CLineShape::Transform
- //----------------------------------------------------------------------------------------
-
- void FW_CLineShape::Transform(Environment *ev, ODTransform* transform)
- {
- fStart.Transform(ev, transform);
- fEnd.Transform(ev, transform);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CLineShape::InverseTransform
- //----------------------------------------------------------------------------------------
-
- void FW_CLineShape::InverseTransform(Environment *ev, ODTransform* transform)
- {
- fStart.InverseTransform(ev, transform);
- fEnd.InverseTransform(ev, transform);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CLineShape::Inset
- //----------------------------------------------------------------------------------------
-
- void FW_CLineShape::Inset(FW_CFixed x, FW_CFixed y)
- {
- if (fStart.x > fEnd.x)
- {
- fStart.x += x;
- fEnd.x -= x;
- }
- else if (fStart.x < fEnd.x)
- {
- fStart.x -= x;
- fEnd.x += x;
- }
- else
- {
- if (fStart.y < fEnd.y)
- {
- fStart.x -= x;
- fEnd.x += x;
- }
- else
- {
- fStart.x += x;
- fEnd.x -= x;
- }
- }
-
- if (fStart.y > fEnd.y)
- {
- fStart.y += y;
- fEnd.y -= y;
- }
- else if (fStart.y < fEnd.y)
- {
- fStart.y -= y;
- fEnd.y += y;
- }
- else
- {
- if (fStart.x < fEnd.x)
- {
- fStart.y -= y;
- fEnd.y += y;
- }
- else
- {
- fStart.y += y;
- fEnd.y -= y;
- }
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CLineShape::MoveShape
- //----------------------------------------------------------------------------------------
-
- void FW_CLineShape::MoveShape(FW_CFixed deltaX, FW_CFixed deltaY)
- {
- fStart.x += deltaX;
- fStart.y += deltaY;
- fEnd.x += deltaX;
- fEnd.y += deltaY;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CLineShape::MoveShapeTo
- //----------------------------------------------------------------------------------------
-
- void FW_CLineShape::MoveShapeTo(FW_CFixed x, FW_CFixed y)
- {
- fEnd.x += x - fStart.x;
- fEnd.y += y - fStart.y;
- fStart.x = x;
- fStart.y = y;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CLineShape::HitTest
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CLineShape::HitTest(FW_CGraphicContext& gc,
- const FW_CPoint& test,
- FW_CFixed tolerance) const
- {
- if(fRenderVerb == FW_kNoRendering)
- return FALSE;
-
- return ::FW_HitTestLine(fStart, fEnd, test, tolerance);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CLineShape::Copy
- //----------------------------------------------------------------------------------------
-
- FW_CShape* FW_CLineShape::Copy() const
- {
- return FW_NEW(FW_CLineShape, (*this));
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CLineShape::GetGeometry
- //----------------------------------------------------------------------------------------
-
- void FW_CLineShape::GetGeometry(FW_CPoint& start, FW_CPoint& end) const
- {
- start = fStart;
- end = fEnd;
- }
-
-
- //----------------------------------------------------------------------------------------
- // FW_CLineShape::SetGeometry
- //----------------------------------------------------------------------------------------
-
- void FW_CLineShape::SetGeometry(const FW_CPoint& start, const FW_CPoint& end)
- {
- fStart = start;
- fEnd = end;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CLineShape::Flatten
- //----------------------------------------------------------------------------------------
-
- void FW_CLineShape::Flatten(FW_CWritableStream& archive) const
- {
- FW_CShape::Flatten(archive);
-
- archive << fStart;
- archive << fEnd;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CLineShape::Read
- //----------------------------------------------------------------------------------------
-
- void* FW_CLineShape::Read(FW_CReadableStream& archive)
- {
- return FW_NEW(FW_CLineShape, (archive));
- }
-
-